package com.basic.bio.chat.groupchatdemo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

/**
 * @Description:服务器端
 * @Author:Zc9741
 * @QQ:516906531
 */
public class ServerReceiveRunnable implements Runnable{
    private Socket socket;

    public ServerReceiveRunnable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        System.out.println("服务端开始收消息咯。。。");
        try {
            BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line=null;
            while ((line=br.readLine())!=null){
                for (Socket socket1 : Server.sockets) {
                    //判断是否为当前客户端
                    if(socket!=socket1){
                        PrintStream ps = new PrintStream(socket1.getOutputStream());
                        ps.println(line);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

